package chapter5;

/**
 * 构造器的重载
 */
public class Apple {
    private String name;
    private String color;
    private double weight;

    public Apple(String name, String color) {
        this.name = name;
        this.color = color;
    }

    public Apple(String name, String color, double weight) {
        //this调用其他构造器时，必须在构造器的第一行代码调用
        this(name, color);
        this.weight = weight;
    }

    public static void main(String[] args) {
        Apple a1 = new Apple("apple1", "red");
        Apple a2 = new Apple("apple2", "green", 2.5);
        System.out.println("a1 name=" + a1.name + " a1 color=" + a1.color + " a1 weight=" + a1.weight);
        System.out.println("a2 name=" + a2.name + " a2 color=" + a2.color + " a2 weight=" + a2.weight);
    }
}
